﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SurfaceAsteroids
{
    class SpaceObject
    {

        private Vector2 location;
        private float direction;
        private float rotation;
        private float velocity = 1f;
        private float scale = 1f;
        private Microsoft.Xna.Framework.Graphics.Color color = Microsoft.Xna.Framework.Graphics.Color.White;
        private Texture2D texture;
        private bool flaggedForDeletion = false;
        private double rotationSpeed;


        public Vector2 Location
        {
            get { return location; }
            set { location = value; }
        }
        public float Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }
        public float Velocity
        {
            get { return velocity; }
            set { velocity = value; }
        }
        public Microsoft.Xna.Framework.Graphics.Color Color
        {
            get { return color; }
            set { color = value; }
        }
        public float Scale
        {
            get { return scale; }
            set { scale = value; }
        }
        public Texture2D Texture
        {
            get { return texture; }
            set { texture = value; }
        }
        public bool FlaggedForDeletion
        {
            get { return flaggedForDeletion; }
            set { flaggedForDeletion = value; }
        }
        public double RotationSpeed { get { return rotationSpeed; } set { rotationSpeed = value; } }


        public void Move()
        {
            float x = location.X + (float)Math.Sin(direction) * velocity;
            float y = location.Y - (float)Math.Cos(direction) * velocity; //- bc top is zero
            location = new Vector2(x, y);

            if (!ObjectType().Equals("shot"))
                RotateObject();
        }

        virtual public string ObjectType()
        {
            return "base";
        }

        public void RotateObject()
        {
            rotation = (float)((rotation + rotationSpeed) % (Math.PI * 2));
        }

        public SpaceObject(Vector2 loc, float rot, float vel, Microsoft.Xna.Framework.Graphics.Color col, float sca, Texture2D tex)
        {
            location = loc;
            rotation = direction = rot;
            velocity = vel;
            color = col;
            scale = sca;
            texture = tex;
            Random rand = new Random();
            rotationSpeed = ((float)rand.NextDouble()/20) - (0.025);
        }


    }
}
